package com.lxl.rabbitmq1.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TopicConfig {

    @Bean
    public TopicExchange topicExchange() {
        //durable是否实例化持久化，autodelete是否自动删除
        TopicExchange directExchange = new TopicExchange("exchange.topic");

        return directExchange;
    }

    //湖南的消息队列
    @Bean
    public Queue hunanQueue() {
        Queue queue = new Queue("hunan.queue");
        return queue;
    }

    //湖北的消息队列
    @Bean
    public Queue hubeiQueue() {
        Queue queue = new Queue("hubei.queue");
        return queue;
    }

    //新闻的消息队列
    @Bean
    public Queue newsQueue() {
        Queue queue = new Queue("news.queue");
        return queue;
    }

    //天气的消息队列
    @Bean
    public Queue weatherQueue() {
        Queue queue = new Queue("weather.queue");
        return queue;
    }
    @Bean
    Binding bindingChinaQueue(){
        //#：代表0个或多个关键词
        //*：代表1个单词
        return BindingBuilder.bind(hunanQueue()).to(topicExchange()).with("hunan.#");
    }
    @Bean
    Binding bindingJapanQueue(){
        return BindingBuilder.bind(hubeiQueue()).to(topicExchange()).with("hubei.#");
    }
    @Bean
    Binding bindingNewsQueue(){
//        return BindingBuilder.bind(newsQueue()).to(topicExchange()).with("#.news");
        return BindingBuilder.bind(newsQueue()).to(topicExchange()).with("*.news");
    }
    @Bean
    Binding bindingWeatherQueue(){
        return BindingBuilder.bind(weatherQueue()).to(topicExchange()).with("#.weather");
    }



}